package br.com.bestOffer.util;

import java.io.IOException;
import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 * @author Franklin Bourguignon
 *
 */
public abstract class BaseManagedBean implements Serializable  {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4426278052056653650L;

	protected void addMessageInfo(String summary) {  
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, summary,  null));  
    }  
  
    protected void addMessageWarn(String summary) {  
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, summary, null));  
    }  
  
    protected void addMessageError(String summary) {  
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, null));  
    }  
  
    protected void addMessageFatal(String summary) {  
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, summary, null));  
    }
	
	public String paginaInicial(){
		return BestOfferConstantes.PAGINA_HOME;
	}
	
	public void direcionaPaginaAjax(String pagina,String mensagem) throws IOException{
		FacesContext context = FacesContext.getCurrentInstance();
		context.getExternalContext().getFlash().setKeepMessages(true);
		context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, mensagem,  null)); 
		context.getExternalContext().redirect(pagina);

	}
	




}  

